import React, { useEffect, useState } from "react";
import { Select, SelectProps } from "antd";
import { User } from "f2e-middle-rbac/lib/interface";
import { api_users } from "../../apis";


const UserSelect = (props: SelectProps) => {
    const [users, setUsers] = useState<User[]>([]);

    useEffect(function () {
        api_users().then(setUsers)
    }, [])

    return <Select
        {...props}
        options={users.map(u => {
            return {
                label: u.nickname,
                value: u.username,
            }
        })}
    />
}

export default UserSelect;